﻿
var bSubmit = false;
function doSubmit(btnid){
    bSubmit = true;
    $(btnid).click();
}

function $(s){
    return document.getElementById(s);
}

//window.alert = _alert_msg_show;
				
function dialog(){
	
	this.titile = '';
	this.width = 300;
	this.height = 100;
	this.src = "";
	this.path = "../images/";
	
	this.btnWidth = 100;
	this.okBtnValue = "确认";
	this.cancelBtnValue = "取消";
			   	
    this.getClose = function(){	
		var sClose = '<input type="image" id="dialogBoxClose" onclick="new dialog().reset();" src="' + this.path + 'dialogClose0.gif" border="0" width="17" height="17" onmouseover="this.src=\'' + this.path + 'dialogCloseF.gif\';" onmouseout="this.src=\'' + this.path + 'dialogClose0.gif\';" align="absmiddle" />';
        return sClose;		
    }
	this.getFunc = function(){
        var sFunc = '\
            <input id="dialogOk" class="commonbutton" onmouseover="this.className=\'commonbutton_mouseover\';" onmouseout="this.className=\'commonbutton\';" type="button" style="width:'+ this.btnWidth + 'px;height:22px;line-height:20px;" value="'+ this.okBtnValue + '" onclick="new dialog().reset();" />\
	       <input id="dialogCancel" class="commonbutton" onmouseover="this.className=\'commonbutton_mouseover\';" onmouseout="this.className=\'commonbutton\';" type="button" style="width:'+ this.btnWidth + 'px;height:22px;line-height:20px;margin-left:10px;" value="'+ this.cancelBtnValue + '" onclick="new dialog().reset();" />';
	    return sFunc;
    }
    this.getBody = function(){
        var sFunc = this.getFunc();
	    var sBody = '\
		<table style="background-color:#f1f1f1;width:100%;height:100%;empty-cells:show;border-collapse:collapse;" id="dialogBodyBox" border="0" align="center" cellpadding="0" cellspacing="0">\
			<tr><td style="height:1px;width:100%;" colspan="4" nowrap></td></tr>\
			<tr style="height:100%;">\
				<td width="10" nowrap></td>\
				<td width="80" align="center" valign="middle" nowrap><img align="absmiddle" id="dialogBoxFace" src="' + this.path + '1.gif" /></td>\
				<td id="dialogMsg" style="width:100%;font-size:12px;WORD-WRAP:break-word;"></td>\
				<td width="10" nowrap></td>\
			</tr>\
			<tr><td style="height:1px;width:100%;" colspan="4" align="center" nowrap></td></tr>\
			<tr><td style="height:40px;" id="dialogFunc" colspan="4" align="center" nowrap>' + sFunc + '</td></tr>\
			<tr><td style="height:1px;" colspan="4" align="center" nowrap></td></tr>\
		</table>\
	    ';
	    return sBody;
    }
    this.getBox = function(){
        var sClose = this.getClose(); 
        var sBody = this.getBody();
        
    	var sBox = '\
		<table id="dialogBox" width="' + this.width + '" border="0" cellpadding="0" cellspacing="0" style="background-color:#f1f1f1;border:1px solid #000;display:none;z-index:10;">\
			<tr height="1" bgcolor="#D6E3EB"><td></td></tr>\
			<tr height="25" bgcolor="#6795B4">\
				<td>\
					<table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0">\
						<tr>\
							<td width="6"></td>\
							<td id="dialogBoxTitle" onmousedown="new dialog().moveStart(event, \'dialogBox\')" style="color:#fff;cursor:move;font-size:12px;font-weight:bold;">&nbsp;</td>\
							<td id="dialogClose" width="27" align="right" valign="middle">\
								' + sClose + '\
							</td>\
							<td width="6"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr height="2" bgcolor="#EDEDED"><td></td></tr>\
			<tr id="dialogHeight" style="height:' + this.height + '">\
				<td id="dialogBody" bgcolor="#ffffff">' + sBody + '</td>\
			</tr>\
		</table>\
		<div id="dialogBoxShadow" style="display:none;z-index:9;"></div>\
	    ';
	    
	    return sBox;
    }
    this.getBG = function(){
	    var sBG = '\
		    <div id="dialogBoxBG" style="position:absolute;top:0px;left:0px;width:100%;height:100%;background:url(' + this.path + 'blank.gif);"></div>\
	    ';	    
	    return sBG;
	}
    
	function $(_sId){
	   return document.getElementById(_sId);
    }
    
	this.show = function(){
		this.middle('dialogBox');
		this.shadow(); 
		//window.onscroll=this.middle('dialogBox');
		//$("dialogBoxBG").style.width = document.body.scrollWidth;
		//$("dialogBoxBG").style.height = document.body.scrollHeight;
	}
	this.reset = function(){
	   $('dialogBox').style.display='none';
	   $('dialogBoxBG').style.display='none';
	   $('dialogBoxShadow').style.display = "none";
	   $('dialogBody').innerHTML = this.getBody();
	}
	this.html = function(_sHtml){
	   $("dialogBody").innerHTML = _sHtml;this.show();
    }
	this.init = function(){
		$('dialogCase') ? $('dialogCase').parentNode.removeChild($('dialogCase')) : function(){};
		var oDiv = document.createElement('span');
		oDiv.id = "dialogCase";
		oDiv.innerHTML = this.getBG() + this.getBox();
		document.body.appendChild(oDiv);
		$('dialogBoxBG').style.height = document.body.scrollHeight;
	}
	this.button = function(_sId, _sFuc){
		if($(_sId)){
			$(_sId).style.display = '';
			if($(_sId).addEventListener){
				if($(_sId).act){$(_sId).removeEventListener('click', function(){eval($(_sId).act)}, false);}
				$(_sId).act = _sFuc;
				$(_sId).addEventListener('click', function(){eval(_sFuc)}, false);
			}else{
				if($(_sId).act){$(_sId).detachEvent('onclick', function(){eval($(_sId).act)});}
				$(_sId).act = _sFuc;
				$(_sId).attachEvent('onclick', function(){eval(_sFuc)});
			}
		}
	}
	this.shadow = function(){
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		oShadow['style']['position'] = "absolute";
		oShadow['style']['background']	= "#000";
		oShadow['style']['display']	= "";
		oShadow['style']['opacity']	= "0.2";
		oShadow['style']['filter'] = "alpha(opacity=20)";
		oShadow['style']['top'] = oDialog.offsetTop + 6;
		oShadow['style']['left'] = oDialog.offsetLeft + 6;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}
	this.open = function(_sUrl, _sMode){
		this.show();
		if(!_sMode || _sMode == "no" || _sMode == "yes"){
			$("dialogBody").innerHTML = "<iframe width='100%' height='100%' src='" + _sUrl + "' frameborder='0' scrolling='" + _sMode + "'></iframe>";
		}
	}
	this.showWindow = function(_sUrl, _iWidth, _iHeight, _sMode, _sTitle){
		var oWindow;
		var sLeft = (screen.width) ? (screen.width - _iWidth)/2 : 0;
		var iTop = -80 + (screen.height - _iHeight)/2;
		iTop = iTop > 0 ? iTop : (screen.height - _iHeight)/2;
		var sTop = (screen.height) ? iTop : 0;
		if(window.showModalDialog && _sMode == "m"){
			oWindow = window.showModalDialog(_sUrl,_sTitle,"dialogWidth:" + _iWidth + "px;dialogheight:" + _iHeight + "px");
		} else {
			oWindow = window.open(_sUrl, _sTitle, 'height=' + _iHeight + ', width=' + _iWidth + ', top=' + sTop + ', left=' + sLeft + ', toolbar=no, menubar=no, scrollbars=' + _sMode + ', resizable=no,location=no, status=no');
			this.reset();
		}
	}
	this.event = function(_sMsg, _sOk, _sCancel, _sClose){
		$('dialogFunc').innerHTML = this.getFunc();
		$('dialogClose').innerHTML = this.getClose();
		$('dialogBodyBox') == null ? $('dialogBody').innerHTML = this.getBody() : function(){};
		$('dialogMsg') ? $('dialogMsg').innerHTML = _sMsg  : function(){};
		_sOk && _sOk != "" ? this.button('dialogOk', _sOk)| $('dialogOk').focus() : $('dialogOk').style.display = 'none';
		_sCancel && _sCancel != "" ? this.button('dialogCancel', _sCancel) : $('dialogCancel').style.display = 'none';
		//_sOk ? this.button('dialogOk', _sOk) : _sOk == "" ? function(){} : $('dialogCancel').style.display = 'none';
		//_sCancel ? this.button('dialogCancel', _sCancel) : _sCancel == "" ? function(){} : $('dialogCancel').style.display = 'none';
		_sClose ? this.button('dialogBoxClose', _sClose) : function(){};
		this.show();
	}
	this.set = function(_oAttr, _sVal){
		var oShadow = $('dialogBoxShadow');
		var oDialog = $('dialogBox');
		var oHeight = $('dialogHeight');

		if(_sVal != ''){
			switch(_oAttr){
				case 'title':
					$('dialogBoxTitle').innerHTML = _sVal;
					this.title = _sVal;
					break;
				case 'width':
					oDialog['style']['width'] = _sVal;
					this.width = _sVal;
					break;
				case 'height':
					oHeight['style']['height'] = _sVal;
					this.height = _sVal;
					break;
				case 'src':
					if(parseInt(_sVal) > 0){
						$('dialogBoxFace') ? $('dialogBoxFace').src = this.path + _sVal + '.gif' : function(){};
					}else{
						$('dialogBoxFace') ? $('dialogBoxFace').src = _sVal : function(){};
					}
					this.src = _sVal;
					break;
				case 'btnWidth':
				    this.btnWidth = _sVal ;
				    break;
				case 'okBtnValue':
				    $('dialogOk')?$('dialogOk').value = _sVal : this.okBtnValue = _sVal ;
				    break;
				case 'cancelBtnValue':
				    $('dialogCancel')?$('dialogCancel').value = _sVal : this.cancelBtnValue = _sVal;
				    break;
			}
		}
		this.middle('dialogBox');
		oShadow['style']['top'] = oDialog.offsetTop + 6;
		oShadow['style']['left'] = oDialog.offsetLeft + 6;
		oShadow['style']['width'] = oDialog.offsetWidth;
		oShadow['style']['height'] = oDialog.offsetHeight;
	}
	this.moveStart = function (event, _sId){
		var oObj = $(_sId);
		oObj.onmousemove = mousemove;
		oObj.onmouseup = mouseup;
		oObj.setCapture ? oObj.setCapture() : function(){};
		oEvent = window.event ? window.event : event;
		var dragData = {x : oEvent.clientX, y : oEvent.clientY};
		var backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
		function mousemove(){
			var oEvent = window.event ? window.event : event;
			var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
			var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
			oObj.style.left = iLeft;
			oObj.style.top = iTop;
			$('dialogBoxShadow').style.left = iLeft + 6;
			$('dialogBoxShadow').style.top = iTop + 6;
			dragData = {x: oEvent.clientX, y: oEvent.clientY};
			
		}
		function mouseup(){
			var oEvent = window.event ? window.event : event;
			oObj.onmousemove = null;
			oObj.onmouseup = null;
			if(oEvent.clientX < 1 || oEvent.clientY < 1 || oEvent.clientX > document.body.clientWidth || oEvent.clientY > document.body.clientHeight){
				oObj.style.left = backData.y;
				oObj.style.top = backData.x;
				$('dialogBoxShadow').style.left = backData.y + 6;
				$('dialogBoxShadow').style.top = backData.x + 6;
			}
			oObj.releaseCapture ? oObj.releaseCapture() : function(){};
		}
	}
	this.hideModule = function(_sType, _sDisplay){
		var aIframe = parent.document.getElementsByTagName("iframe");aIframe=0;
		var aType = document.getElementsByTagName(_sType);
		var iChildObj, iChildLen;
		for (var i = 0; i < aType.length; i++){
			aType[i].style.display	= _sDisplay;
		}
		for (var j = 0; j < aIframe.length; j++){
			iChildObj = document.frames ? document.frames[j] : aIframe[j].contentWindow;
			iChildLen = iChildObj.document.body.getElementsByTagName(_sType).length;
			for (var k = 0; k < iChildLen; k++){
				iChildObj.document.body.getElementsByTagName(_sType)[k].style.display = _sDisplay;
			}
		}
	}
	this.middle = function(_sId){
		document.getElementById(_sId)['style']['display'] = '';
		document.getElementById(_sId)['style']['position'] = "absolute";
				
//原程序默认居中
//		var sClientWidth = parent ? parent.document.body.clientWidth : document.body.clientWidth;
//		var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
//		var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
//		document.getElementById(_sId)['style']['left'] = (document.body.clientWidth / 2) - (document.getElementById(_sId).offsetWidth / 2);
//		var sTop = -80 + (sClientHeight / 2 + sScrollTop) - (document.getElementById(_sId).offsetHeight / 2);
//		document.getElementById(_sId)['style']['top'] = sTop > 0 ? sTop : (sClientHeight / 2 + sScrollTop) - (document.getElementById(_sId).offsetHeight / 2);
		
		
//普通居中		
//	document.getElementById(_sId).style.posLeft    =   document.body.scrollLeft   +   (document.body.clientWidth   -   document.getElementById(_sId).clientWidth)/2;   
//  document.getElementById(_sId).style.posTop    =   document.body.scrollTop   +   (document.body.clientHeight   -   document.getElementById(_sId).clientHeight)/2;   


		
//  Web标准居中
        var x=0,y=0;
        x = (document.documentElement.scrollLeft || document.body.scrollLeft);
        y = (document.documentElement.scrollTop || document.body.scrollTop);
  
/**//*一下这段这么复杂的处理方法,是为了符合最新web标准,因为在aspx页面中会默认加入
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
新的标准中不支持document.body.clientHeight 属性,它是MSIE所有的
*/
        var theWidth=0,theHeight=0;
  
        if (window.innerWidth) 
        { 
            theWidth = window.innerWidth 
            theHeight = window.innerHeight 
        } 
        else if (document.documentElement && document.documentElement.clientWidth) 
        { 
            theWidth = document.documentElement.clientWidth 
            theHeight = document.documentElement.clientHeight 
        } 
        else if (document.body) 
        { 
            theWidth = document.body.clientWidth 
            theHeight = document.body.clientHeight 
        }
  
        //做div居中处理
        document.getElementById(_sId).style.left = (theWidth  - document.getElementById(_sId).offsetWidth)/2+x;
        document.getElementById(_sId).style.top = (theHeight - document.getElementById(_sId).offsetHeight)/2+y; 				
	}
}

function _alert_msg_show(msg,title,click){

    title = title ? title : '系统提示信息';
    click = click ? click : ' ';

    var dg=new dialog();
	dg.init();
    dg.set('src', 1);
    dg.set('title', title);	
	dg.event(msg, click, '', click);
}

function _error_msg_show(msg, title, click )
{
    msg = "<b><span style='color:red'>" + msg + "</span></b>"
    click = click ? click : ' ';
    title = title ? title : '系统提示信息';

    var dg=new dialog();
    dg.init();
    dg.set('src', 2);
    dg.set('title', title);
    dg.event(msg, click, '', click);
}

function _win_error_msg_show(msg, click, top, left, width, height)
{
    msg = "<b><span style='color:red'>" + msg + "</span></b>"
    click = click ? click : ' ';
    title = '系统提示信息';
    top = top ? top : 80;

    var dg=new dialog();
    dg.init();

    dg.set('src', 2);
    dg.set('title', title);
	
    if (width)
    {
        dg.set('width', width);
    }
    if (height)
    {
        dg.set('height', height);
    }

    dg.event(msg, click, '', click);

	
    if (left)
    {
         document.getElementById('dialogBox')['style']['left'] = left;
         document.getElementById('dialogBoxShadow')['style']['left'] = left;
    }
    if (top)
    {
	    document.getElementById('dialogBox')['style']['top'] = top;
	    document.getElementById('dialogBoxShadow')['style']['top'] = top;
    }

}

function _confirm_msg_show(msg, title, click_ok, click_no)
{
    click_ok = click_ok ? click_ok : ' ';
    click_no = click_no ? click_no : ' ';
    title = title ? title : '系统提示信息';

    dg=new dialog();
    dg.init();
    dg.set('src', 3);
    dg.set('title', title);
    dg.event(msg, click_ok, click_no, click_no);
}

function _win_confirm_msg_show(msg, title, click_ok, click_no, top, left, width, height)
{
    click_ok = click_ok ? click_ok : ' ';
    click_no = click_no ? click_no : ' ';
    title = '系统提示信息';
    top = top ? top : 80;

    dg=new dialog();
    dg.init();
    dg.set('src', 3);   // smile
    dg.set('title', title);

    if (width)
    {
        dg.set('width', width);
    }
    if (height)
    {
        dg.set('height', height);
    }

    dg.event(msg, click_ok, click_no, click_no);

    if (left)
    {
         document.getElementById('dialogBox')['style']['left'] = left;
         document.getElementById('dialogBoxShadow')['style']['left'] = left;
    }
    if (top)
    {
         document.getElementById('dialogBox')['style']['top'] = top;
         document.getElementById('dialogBoxShadow')['style']['top'] = top;
    }
}
